package com.gt.web.api.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * <p>
 * Page
 * </p>
 *
 * @author: WeiHuan
 * @version:1.0
 * @date: 2024/2/5 21:23
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目的
 */


@Data
@ApiModel(description = "分页实体")
public class PageResult<T> {



    @ApiModelProperty(value = "列表对象")
    @JsonProperty(value = "List")
    private T List;
    @ApiModelProperty(value = "分页信息")
    @JsonProperty(value = "PageInfo")
    private InnerPage PageInfo;
    public PageResult(T  data, Page page) {
        this.List = data;
        this.PageInfo = new InnerPage(page);
    }
    public PageResult(T  data, EZRPageResult ezrResult) {
        this.List = data;
        this.PageInfo = new InnerPage(ezrResult);
    }

    @Getter
    @Setter
    @ApiModel(value = "分页信息")
    public static class InnerPage {
        @ApiModelProperty(value = "总条数",required = true)
        @JsonProperty(value = "Total")
        private Long Total;

        @ApiModelProperty(value = "每页显示条数")
        @JsonProperty(value = "Size")
        private Long Size;

        @ApiModelProperty(value = "当前页")
        @JsonProperty(value = "Current")
        private Long Current;

        public InnerPage(Page page) {
            this.Total = page.getTotal();
            this.Size = page.getSize();
            this.Current = page.getCurrent();
            if (page.getRecords().size()==0) {
                this.Total = 0L;
                this.Size = 0L;
                this.Current = 1L;
            }
        }
        public InnerPage(EZRPageResult ezrResult) {
            this.Total = ezrResult.getTotalCount();
            this.Size = ezrResult.getPageTotal();
            // this.Current = ezrResult.ge();

        }
    }
}